<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/calendar.js"></script>
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var contractCode = document.getElementById("contractCode");
		var customerName = document.getElementById("customerName");
		var startContractCost = document.getElementById("startContractCost");
		var endContractCost = document.getElementById("endContractCost");
		var purchaseDesc = document.getElementById("purchaseDesc");
		var startContractDate = document.getElementById("startContractDate");
		var endContractDate = document.getElementById("endContractDate");
		var startBackCost = document.getElementById("startBackCost");
		var endBackCost = document.getElementById("endBackCost");
		var invoiceDesc = document.getElementById("invoiceDesc");
		var salePersonId = document.getElementById("salePersonId");
		if(startContractCost.value != ''){
			if(endContractCost.value == ''){
				alert("请输入合同结束金额！");
				return false;
			}
		}
		if(endContractCost.value != ''){
			if(startContractCost.value == ''){
				alert("请输入合同开始金额！");
				return false;
			}
		}
		if(startContractCost.value != '' && endContractCost.value != ''){
			var d1 = startContractCost.value;
			var d2 = endContractCost.value;
			if(Number(d1) - Number(d2) > 0){
				alert("合同开始金额不能大于等于合同结束金额，请重新输入合同开始金额！");
				return false;
			}
		}

		if(startBackCost.value != ''){
			if(endBackCost.value == ''){
				alert("请输入回款结束金额！");
				return false;
			}
		}
		if(endBackCost.value != ''){
			if(startBackCost.value == ''){
				alert("请输入回款开始金额！");
				return false;
			}
		}
		if(startBackCost.value != '' && endBackCost.value != ''){
			var d1 = startBackCost.value;
			var d2 = endBackCost.value;
			if(Number(d1) - Number(d2) > 0){
				alert("回款开始金额不能大于等于回款结束金额，请重新输入回款开始金额！");
				return false;
			}
		}

		
		
		if(startContractDate.value != ''){
			if(endContractDate.value == ''){
				alert("请选择签约结束日期！");
				return false;
			}
		}
		if(endContractDate.value != ''){
			if(startContractDate.value == ''){
				alert("请选择签约开始日期！");
				return false;
			}
		}
		if(startContractDate.value != '' && endContractDate.value != ''){
			var d1 = (startContractDate.value).replace("-","/");
			var d2 = (endContractDate.value).replace("-","/");
			if(Date.parse(d1) - Date.parse(d2) > 0){
				alert("签约开始日期不能比签约结束日期早，请重新选择签约开始日期！");
				return false;
			}
		}
		
		if(contractCode.value == '' && customerName.value == '' && startContractCost.value == '' && endContractCost.value == '' && purchaseDesc.value == '' && startContractDate.value == '' 
			&& endContractDate.value == '' && startBackCost.value == '' && endBackCost.value == '' && invoiceDesc.value == '' &&salePersonId.value == ''){
			alert("请输入查询条件！");
			return false;
		}
		return true;
	}
	
	function queryContract(){
		if(checkForm()){
			var contractCode = document.getElementById("contractCode").value;
			var customerName = document.getElementById("customerName").value;
			var startContractCost = document.getElementById("startContractCost").value;
			var endContractCost = document.getElementById("endContractCost").value;
			var purchaseDesc = document.getElementById("purchaseDesc").value;
			var startContractDate = document.getElementById("startContractDate").value;
			var endContractDate = document.getElementById("endContractDate").value;
			var startBackCost = document.getElementById("startBackCost").value;
			var endBackCost = document.getElementById("endBackCost").value;
			var invoiceDesc = document.getElementById("invoiceDesc").value;
			var salePersonId = document.getElementById("salePersonId").value;
			
			var values = "";
			values = contractCode + "," + customerName + "," + startContractCost + "," + endContractCost + ",";
			values += purchaseDesc + "," + startContractDate + "," + endContractDate + "," + startBackCost + "," + endBackCost+ "," + invoiceDesc+ "," + salePersonId ;
			
			window.returnValue = values;
			self.close();
		}
	}
	
-->
</script>
</head>
<body><br>
	<div class="tools">
		<input class="btn1" type="button" value="确 定" onclick="queryContract()"/>&nbsp;&nbsp;
		<input class="btn1" type="button" value="取 消" onclick="window.close();"/>&nbsp;&nbsp;
	</div>
	
<table class="table1">
	<tr>
		<td>
			<table class="table_input" cellpadding="0" cellspacing="0" style="margin: 0 0 0 50px;">
				<tr>
					<td width="20%">合同编号：</td>
					<td><input id="contractCode" name="contractCode" class="input_long" type="text"/></td>
				</tr>
				<tr>
					<td width="20%">客户名称：</td>
					<td><input id="customerName" name="customerName" class="input_long" type="text"/></td>
				</tr>
				<!-- 
				<tr>
					<td width="20%">销售代表：</td>
					<td><input class="input1" type="text"/></td>
				</tr>
				 -->
				 <c:if test="${isViewAllContract == 1}">
				 <tr>
					<td width="20%">销售代表：</td>
					<td>
						<select id="salePersonId" name="salePersonId">
							<option value="">----------请选择----------</option>
							<c:forEach var="user" items="${users}">
								<option value="${user.id}">${user.userName}</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				</c:if>
				<tr>
					<td width="20%">合同金额：</td>
					<td>
						<input id="startContractCost" name="startContractCost" class="input1" type="text" size="5"/>--
						<input id="endContractCost" name="endContractCost" class="input1" type="text" size="5"/>元
					</td>
				</tr>
				<tr>
					<td width="20%">商品名称：</td>
					<td><input id="purchaseDesc" name="purchaseDesc" class="input_long" type="text"/></td>
				</tr>
				<tr>
					<td width="20%">回款金额：</td>
					<td>
						<input id="startBackCost" name="startBackCost" class="input1" type="text" size="5"/>--
						<input id="endBackCost" name="endBackCost" class="input1" type="text" size="5"/>元
					</td>
				</tr>
				<tr>
					<td width="20%">签约日期：</td>
					<td>
						<input id="startContractDate" name="startContractDate" class="input1" type="text" 
							onclick="calendar(this,'yyyy-MM-dd');" readonly="readonly"/>--
						<input id="endContractDate" name="endContractDate" class="input1" type="text" 
							onclick="calendar(this,'yyyy-MM-dd');" readonly="readonly"/>
					</td>
				</tr>
				<tr>
					<td width="20%">开票备注：</td>
					<td><input id="invoiceDesc" name="invoiceDesc" class="input_long" type="text"/></td>
				</tr>
				
			</table>
		</td>
	</tr>
</table>	
</body>
</html>